package com.xy.farm.activity.farm;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.xy.farm.R;
import com.xy.farm.activity.adapter.PageAdapter;
import com.xy.farm.activity.base.BaseActivity;
import com.xy.farm.activity.farm.adapter.FarmDetailsAdapter;

import java.util.ArrayList;
import java.util.List;

public class FarmDetailsActivity extends BaseActivity
{
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private PageAdapter adapter;
    private List<View> views = new ArrayList<>();
    private List<String> strings = new ArrayList<>();
    private FrameLayout layoutNull1;
    private FrameLayout layoutNull2;
    private FrameLayout layoutNull3;
    private FrameLayout layoutNull4;
    private RecyclerView recyclerView1;
    private RecyclerView recyclerView2;
    private RecyclerView recyclerView3;
    private RecyclerView recyclerView4;
    private FarmDetailsAdapter adapter1;
    private FarmDetailsAdapter adapter2;
    private FarmDetailsAdapter adapter3;
    private FarmDetailsAdapter adapter4;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_farm_details);
        setTitle("广州从化农场");
        findViewById(R.id.btn_back).setOnClickListener(this);
        tabLayout = findViewById(R.id.tabLayout);
        viewPager = findViewById(R.id.viewPager);
        strings.add("已购地");
        strings.add("果园地");
        strings.add("菜园地");
        strings.add("养殖地");
        views.add(LayoutInflater.from(this).inflate(R.layout.layout_farm_details, null));
        views.add(LayoutInflater.from(this).inflate(R.layout.layout_farm_details, null));
        views.add(LayoutInflater.from(this).inflate(R.layout.layout_farm_details, null));
        views.add(LayoutInflater.from(this).inflate(R.layout.layout_farm_details, null));
        layoutNull1 = views.get(0).findViewById(R.id.layout_null);
        layoutNull2 = views.get(1).findViewById(R.id.layout_null);
        layoutNull3 = views.get(2).findViewById(R.id.layout_null);
        layoutNull4 = views.get(3).findViewById(R.id.layout_null);
        recyclerView1 = views.get(0).findViewById(R.id.recyclerView);
        recyclerView2 = views.get(1).findViewById(R.id.recyclerView);
        recyclerView3 = views.get(2).findViewById(R.id.recyclerView);
        recyclerView4 = views.get(3).findViewById(R.id.recyclerView);
        recyclerView1.setHasFixedSize(true);
        recyclerView2.setHasFixedSize(true);
        recyclerView3.setHasFixedSize(true);
        recyclerView4.setHasFixedSize(true);
        recyclerView1.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        recyclerView2.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        recyclerView3.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        recyclerView4.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        tabLayout.setupWithViewPager(viewPager);
        viewPager.setAdapter((adapter = new PageAdapter(views, strings)));
        tabLayout.setTabsFromPagerAdapter(adapter);
        layoutNull1.setVisibility(View.VISIBLE);
        layoutNull2.setVisibility(View.GONE);
        layoutNull3.setVisibility(View.GONE);
        layoutNull4.setVisibility(View.GONE);
        recyclerView1.setAdapter((adapter1 = new FarmDetailsAdapter()));
        recyclerView2.setAdapter((adapter2 = new FarmDetailsAdapter()));
        recyclerView3.setAdapter((adapter3 = new FarmDetailsAdapter()));
        recyclerView4.setAdapter((adapter4 = new FarmDetailsAdapter()));
    }
}
